package isquirrel.semantic;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import isquirrel.UserManager;
import isquirrel.beans.Property;
import isquirrel.beans.User;
import isquirrel.util.HibernateUtil;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.junit.Test;

public class DBpediaTest {
	
//	@Test
	public void testBroaderOf()
	{
		DBpedia d = new DBpedia();
		
		for( String s : d.getMoreSpecificSubjects(d.getSubjects("computer science")))
			System.out.println(s);
		
		System.out.println();
		
		for( String s : d.getMoreSpecificSubjects(d.getSubjects("travelling")))
			System.out.println(s);
		
		System.out.println();
		
		for( String s : d.getMoreSpecificSubjects(d.getSubjects("music")))
			System.out.println(s);
	}
	
//	@Test
	public void testGetPageInfo() 
	{
		HibernateUtil.beginTransaction();
		User u = UserManager.getUser(1L);
		DBpedia dbPedia = new DBpedia();
		List<Property> wikiProperties= dbPedia.getPageInformation("http://en.wikipedia.org/wiki/Bach");
		Iterator<Property> wiki_iter = wikiProperties.iterator();
		while (wiki_iter.hasNext()){
			u.addProperty(wiki_iter.next());
		}
		HibernateUtil.commit();
	}
	
	@Test
	public void testGettingSubjects()
	{
		DBpedia dbPedia = new DBpedia();
		
		Set<String> s1 = dbPedia.getSubjects("Computer Sciences"); // get with redirect
		Set<String> s2 = dbPedia.getSubjects("Computer science ");
		
		assertEquals(s1, s2);
		
		assertNull(dbPedia.getSubjects("non existant thing") );
		
		assertNotSame(dbPedia.getSubjects("xyz"), s2);
		
		System.out.println("0:");
		for ( String s : s2)
			System.out.println(s);
		System.out.println("1:");
		for ( String s : dbPedia.getSubjects("Religion"))
			System.out.println(s);

		System.out.println("2:");
		for ( String s : dbPedia.getSubjects("Advertising"))	//with Redirect
			System.out.println(s);

		System.out.println("3:");
		for ( String s : dbPedia.getSubjects("Law"))
			System.out.println(s);
		
	}
	
//	@Test
	public void testQuerying()
	{
		/*
		DBpedia dbPedia = new DBpedia();
		Property property = new Property(
				"http://www.w3.org/2004/02/skos/core#subject",
				"http://dbpedia.org/resource/Category:Health_disasters");
		Property three = new Property(
				"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
				"http://dbpedia.org/class/yago/Pandemics");
		Property two = new Property(
				"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
				"http://dbpedia.org/class/yago/Syndromes");
		List<Property> list = new LinkedList<Property>();

		list.add(property);
		List<String> urls = dbPedia.getUrls(list);

		for (String url : urls) {
			System.out.println(url);
		}

		System.out.println("*******************************");
		list.add(two);
		urls = dbPedia.getUrls(list);

		for (String url : urls) {
			System.out.println(url);
		}

		System.out.println("*******************************");
		list.add(three);
		urls = dbPedia.getUrls(list);

		for (String url : urls) {
			System.out.println(url);
		}
		System.out.println("+++++++++++++++++++++");
		
		dbPedia.getPageInformation("http://en.wikipedia.org/wiki/Madame_Tussauds");

		System.out.println("+++++++++++++++++++++");
		dbPedia.getPageInformation("http://en.wikipedia.org/wiki/George_W._Bush/");
		
		System.out.println(dbPedia.getHomepage("http://en.wikipedia.org/wiki/Michael_Jackson"));
		System.out.println(dbPedia.getThumbnail("http://en.wikipedia.org/wiki/Madame_Tussauds"));

		System.out.println(dbPedia.getThumbnail("http://en.wikipedia.org/wiki/George_W._Bush"));
		*/
	}
}
